﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using JKF.Substructure;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace JKF.DataModule.SqlServerDAL
{
   public partial class dalGIFT_TYPE:IDAL.IdalGIFT_TYPE
    {
        // 定义要获取哪些字段 GIFT_TPYE_KEY, NAME, USER_CREATE, DATE_CREATE, DATE_UPDATE, MEMO
       private const string FieldShow = "GIFT_TPYE_KEY, NAME, USER_CREATE, DATE_CREATE, DATE_UPDATE";
        private const string FieldOrder = "NAME";
        private const string FieldKey = "GIFT_TPYE_KEY";
        /// <summary>
        /// 获取礼品类别列表
        /// </summary>
        /// <param name="NAME">礼品类别名称</param>
        /// <param name="pageCurrent">当前页码</param>
        /// <param name="pageSize">一页显示多少</param>
        /// <param name="pageCount">总页数</param>
        /// <param name="rowCount">总记录数</param>
        /// <returns>返回DataTable数据</returns>
        public static DataTable GetGift_TypesDAL(string NAME, int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
        {
            var sql = new StringBuilder(@"  1=1 ");
            // 下面组装查询条件
            if (!string.IsNullOrEmpty(NAME))
            {
                sql.AppendFormat(" AND NAME  LIKE '%{0}%'", NAME);
            }
            // 下面调用此方法去查询数据库
            return DataPage.GetPageInfo("dbo.GIFT_TYPE", FieldKey, pageCurrent, pageSize, FieldShow, FieldOrder, sql.ToString(), ref pageCount, ref rowCount).Tables[0];

        }


        /// <summary>
        /// 判断是否存在此名称,true表示存在
        /// </summary>
        /// <param name="shop_name">店面名称</param>
        /// <returns></returns>
        public static bool ExistsGift_TypeNameDAL(string gift_type_name)
        {
            object obj = DB.HR.ExecuteScalar(CommandType.Text, "select count(1) from dbo.GIFT_TYPE where NAME='" + gift_type_name + "'");
            return Convert.ToInt32(obj) > 0;
        }
        /// <summary>
        /// 事务删除礼品类别
        /// </summary>
        /// <param name="shop_code">礼品类别ID</param>
        /// <returns></returns>
        public static string TransactionSQLDeleteDAL(Guid user_key, Guid gift_type_key)
        {
            int result = -1;
            Database db = DB.HR;
            DbCommand dbCommand = db.GetStoredProcCommand("[dbo].[proc_GIFT_TYPEDelete]");
            db.AddInParameter(dbCommand, "@gift_type_key", DbType.Guid, gift_type_key);
            db.AddInParameter(dbCommand, "@user_key", DbType.Guid, user_key);
            db.AddOutParameter(dbCommand, "@result", DbType.Int32, result);
             db.ExecuteNonQuery(dbCommand);
            return dbCommand.Parameters["@result"].Value.ToString();
        }

    }
}
